package com.itheima.contorller;

import com.itheima.domain.Student;
import com.itheima.service.StudentService;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentContorller {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result findAll(){
        List<Student> list=studentService.findALL();
        return Result.success(list);
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Student student=studentService.findById(id);
        return Result.success(student);
    }
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }
    @PostMapping
    public Result save(@RequestBody Student student){
        studentService.save(student);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        studentService.delete(id);
        return Result.success();
    }
}
